package cc.admin.modules.sys.service.impl;

import cc.admin.modules.sys.entity.SysCodeRule;
import cc.admin.modules.sys.mapper.SysCodeRuleMapper;
import cc.admin.modules.sys.service.ISysCodeRuleService;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @Description: 编码规则
 * @Author: cc-admin
 * @Date: 2022-04-18
 * @Version: V1.0.0
 */
@Service
public class SysCodeRuleServiceImpl extends ServiceImpl<SysCodeRuleMapper, SysCodeRule> implements ISysCodeRuleService {

	public String getSerialNumber(String pre, Boolean hasDate, int length, Long serialNumber) {
		String today = DateUtil.format(new Date(), "yyyyMMdd");
		StringBuilder sb = new StringBuilder(pre);
		if (hasDate) {
			sb.append(today);
		}
		if (length > 0) {
			sb.append(String.format("%0" + length + "d", serialNumber));
		}
		return sb.toString();
	}
}
